#pragma once

#include "XTask.h"
#include <string>

struct bufferevent;
class XFtpSession;

class XFtpTask:public XTask
{
public:
    virtual void parse(const std::string &type, const std::string &msg) {}
    virtual void read(bufferevent *bev) {}
    virtual void write(bufferevent *bev) {}
    virtual void handleEvent(bufferevent *bev, short what) {}
    virtual void responseFtpCmd(const std::string &msg);
    virtual void connectDataChannel(XFtpTask *task);
    virtual void disconnectDataChannel();
    virtual void sendData(const std::string &data);
    virtual void sendData(const char *data, size_t size);
    void setCallBack(bufferevent *ev);
    void setSession(XFtpSession *session);
    XFtpTask();
    virtual ~XFtpTask();
protected:
    virtual bool init();
    static void eventHandler(bufferevent *bev, short what, void *arg);
    static void readHandler(bufferevent *bev, void *arg);
    static void writeHandler(bufferevent *bev, void *arg);
protected:
    XFtpSession *mSesssion = nullptr;
};

